package com.academic_system.util;

import org.apache.commons.lang3.StringUtils;

public enum CodeEnum {
    /*
    默认超出活动时间错误
     */
    TIMEOVER(40001, "超出了设置的期限"),
    /*
    默认缺少参数错误
     */
    NULL(40002, "缺少参数"),
    /*
    默认缺少openID
     */
    NULL_OPENID(40003, "缺少openID"),
    /*
    默认登陆失效
     */
    WRONG_TOKEN(403, "登陆失效请重新登陆"),
    /*
    默认无效的重复对象错误
     */
    REPEAT(40004, "存在重复的事件或对象"),
    SERVER_ERROR(500, "服务端错误");

    private String msg;
    private int code;

    CodeEnum(int c, String s) {
        this.code = c;
        this.msg = s;
    }


    public String getMsg() {
        return msg;
    }

    public CodeEnum setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public int getCode() {
        return code;
    }

    public static int getCode(String msg) {
        for (CodeEnum codeEnum : CodeEnum.values()) {
            if (StringUtils.equals(msg, codeEnum.getMsg())) {
                return codeEnum.getCode();
            }
        }
        return 500;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
